<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use ZigaStrgar\Orderable\Orderable;
use Illuminate\Database\Eloquent\SoftDeletes;
class Product extends Model
{
    use Orderable;
    use SoftDeletes;
    protected $dates = ['deleted_at'];
    protected $table = 'product';
    public $timestamps = false;
    //白名单
    protected $fillable = ['user_id','first_type_id','phone','second_type_id','applicant','level','progress_list_id','created_at','updated_at','file','is_download_notice','company'];
    //黑名单
    protected $guarded =[];
    /**
     * 排序方法，默认排序desc
     * @return array
     */
    public function orderable()
    {
        return [
            'updated_at' => 'DESC',
            'level' => 'DESC',
        ];
    }
    public function FirstType()
    {
        return $this->belongsTo('App\Models\FirstType','first_type_id');
    }

    public function SecondType()
    {
        return $this->belongsTo('App\Models\SecondType','second_type_id');
    }

    public function Admin()
    {
        return $this->belongsTo('App\Models\Admin','admin_id');
    }
    public function Progress()
    {
        return $this->hasMany('App\Models\Progress','product_id',"id");
    }
    public function User()
    {
        return$this->belongsTo('App\Models\User','user_id');
    }

    public function Files()
    {
        return$this->hasMany('App\Models\Files','product_id');
    }
    public function Address()
    {
        return$this->belongsTo('App\Models\Address','address_id');
    }


    public function ProgressState()
    {
        return $this->belongsToMany('App\Models\ProgressList',"progress",'product_id',"progress_list_id");
    }



    public function Operation()
    {
        return$this->hasMany('App\Models\Operation','product_id');
    }
}
